package cn.sxw.android.base.provider;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cn.sxw.android.R;
import cn.sxw.android.base.ui.BaseApplication;

/**
 * 自定义状态页工具类
 * <p>
 * Created by ZengCS on 2019/2/20.
 * E-mail:zcs@sxw.cn
 * Add:成都市天府软件园E3-3F
 */
public class CustomStatusPageHelper {
    /**
     * 更新提示信息
     *
     * @param view 状态布局view
     * @param msg  提示信息
     */
    public static void updateTips(View view, String msg) {
        if (view == null) return;
        TextView textView = view.findViewById(R.id.id_tv_status_tips);
        if (textView != null)
            textView.setText(msg);
    }

    /**
     * 更新状态页图标
     *
     * @param view 状态布局view
     * @param icon 图标id
     */
    public static void updateIcon(View view, int icon) {
        if (view == null) return;
        ImageView imageView = view.findViewById(R.id.id_iv_status_icon);
        if (imageView != null)
            imageView.setImageResource(icon);
    }


    /**
     * 创建状态布局，空界面，异常界面均可
     *
     * @param icon 状态图标
     * @param msg  状态提示信息
     * @return
     */
    public static View makeStatusView(int icon, String msg) {
        try {
            View view = LayoutInflater.from(BaseApplication.getContext()).inflate(R.layout.custom_status_page, null, false);
            ImageView imageView = view.findViewById(R.id.id_iv_status_icon);
            TextView textView = view.findViewById(R.id.id_tv_status_tips);
            if (imageView != null)
                imageView.setImageResource(icon);
            if (textView != null)
                textView.setText(msg);
            return view;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 创建LoadingView
     *
     * @param msg 加载信息
     * @return
     */
    public static View makeLoadingView(String msg) {
        try {
            View view = LayoutInflater.from(BaseApplication.getContext()).inflate(R.layout.custom_status_loading, null, false);
            TextView textView = view.findViewById(R.id.id_tv_status_tips);
            if (textView != null)
                textView.setText(msg);
            return view;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
